module.exports = {
  // inputGetName(e) {
  //   let name = e.currentTarget.dataset.name;
  //   let nameMap = {}
  //   if (name.indexOf('.')) {
  //     let nameList = name.split('.')
  //     console.log(nameList)
  //     if (this.data[nameList[0]]) {
  //       nameMap[nameList[0]] = this.data[nameList[0]]
  //     } else {
  //       nameMap[nameList[0]] = {}
  //     }
  //     if(nameList[2]) {
  //       nameMap[nameList[0]][nameList[1]][nameList[2]] = e.detail.value
  //     } else {
  //       nameMap[nameList[0]][nameList[1]] = e.detail.value
  //     }
  //   } else {
  //     nameMap[name] = e.detail.value
  //   }
  //   console.log(nameMap)
  //   return nameMap
  // },

  /**
   * 获取输入框值对象
   */
  inputGetName(e) {
    let that = this
    let name = e.currentTarget.dataset.name
    let index = e.currentTarget.dataset.index
    let isNumberInput = e.currentTarget.dataset.type === 'number' ? true : false
    let nameMap = {}
    if (name.indexOf('.')) {
      let nameList = name.split('.')
      if (this.data[nameList[0]]) {
        nameMap[nameList[0]] = this.data[nameList[0]]
      } else {
        nameMap[nameList[0]] = {}
      }
      if (nameList[2]) {
        if (Array.isArray(this.data[nameList[0]])) {
          nameMap[nameList[0]][index][nameList[1]][nameList[2]] = isNumberInput ? parseInt(e.detail.value) : e.detail.value
        } else {
          nameMap[nameList[0]][nameList[1]][nameList[2]] = isNumberInput ? parseInt(e.detail.value) : e.detail.value
        }
      } else {
        if (Array.isArray(this.data[nameList[0]])) {
          nameMap[nameList[0]][index][nameList[1]] = isNumberInput ? parseInt(e.detail.value) : e.detail.value
        } else {
          nameMap[nameList[0]][nameList[1]] = isNumberInput ? parseInt(e.detail.value) : e.detail.value
        }
      }
    } else {
      nameMap[name] = isNumberInput ? parseInt(e.detail.value) : e.detail.value
    }
    // console.log(nameMap)
    return nameMap
  },
  // 模拟掷骰子工具（均衡）
  shakeDice(diceNum, diceSides) {
    let list = []
    let sum = 0
    for (let i = 0; i < diceNum; i++) {
      list.push(1 + Math.floor(Math.random() * diceSides))
    }
    for (let i = 0; i < list.length; i++) {
      sum += list[i]
    }
    return {
      list,
      sum
    }
  }
}